﻿Public Class ToggleButton
    Inherits Windows.Forms.Button
    Dim _MyColor As Drawing.Color
    Sub New()
        MyBase.New()
        InitializeComponent()
        Me.BackColor = Drawing.Color.Transparent
        Me.FlatStyle = Windows.Forms.FlatStyle.Flat
        Me.Font = New Drawing.Font("Droid Arabic Kufi", 10)
        Me.FlatAppearance.BorderSize = 0
        Me.ForeColor = Drawing.Color.FromArgb(70, 70, 70)
        Me.Cursor = Cursors.Hand
        Me.Size = New Drawing.Size(80, 35)
    End Sub

#Region " Properties"
    Public Property Checked() As Boolean
        Get
            Return CheckBox1.Checked
        End Get
        Set(value As Boolean)
            CheckBox1.Checked = value
        End Set
    End Property

    Public Property CheckedColor() As Drawing.Color
        Get
            Return _MyColor
        End Get
        Set(value As Drawing.Color)
            _MyColor = value
        End Set
    End Property

#End Region

#Region " Control Events"
    Private Sub ToggleButton_Click(sender As Object, e As EventArgs) Handles Me.Click
        If CheckBox1.Checked = False Then
            For Each ctrl As Control In Me.Parent.Controls
                If TypeOf ctrl Is ToggleButton Then
                    TryCast(ctrl, ToggleButton).Checked = False
                End If
            Next
            CheckBox1.Checked = True
        End If
    End Sub


    Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged
        If CheckBox1.Checked Then
            Me.BackColor = _MyColor
            Me.ForeColor = Drawing.Color.FromArgb(231, 231, 231)
        Else
            Me.BackColor = Drawing.Color.Transparent
            Me.ForeColor = Drawing.Color.FromArgb(70, 70, 70)
        End If
    End Sub

    Private Sub ToggleButton_MouseHover(sender As Object, e As EventArgs) Handles Me.MouseHover, Me.MouseEnter, Me.Enter
        If Me.Checked = False Then
            Me.BackColor = Drawing.Color.FromArgb(230, 230, 230)
        End If
    End Sub

    Private Sub ToggleButton_MouseLeave(sender As Object, e As EventArgs) Handles Me.MouseLeave, Me.Leave
        If Me.Checked = False Then
            Me.BackColor = Drawing.Color.Transparent
        End If
    End Sub
#End Region

    ''' <summary>
    ''' Show the about box of the control.
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub ShowAbout()
        MsgBox("Programmed by: Muhammad Yasin" + vbCrLf + "Email: Muhammad-Yasin@outlook.com", MsgBoxStyle.Information, "About Smooth Label")
    End Sub

End Class
